package com.group.controller;
import com.group.entity.CommonResult;
import com.group.entity.wms.PositionEntity;
import com.group.service.PositionService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

@RestController
@RequestMapping("/position")
public class PositionController {
    @Resource
    private PositionService positionService;

    @GetMapping("/findListByWarehouseAreaId/{warehouseAreaId}")
    private CommonResult<?> findListByWarehouseAreaId(@PathVariable("warehouseAreaId")Long warehouseAreaId){
        return CommonResult.success(this.positionService.findListByWarehouseAreaId(warehouseAreaId),"请求成功");
    }

    /**
     * 添加储位信息
     * @param positionEntity
     * @return
     */
    @PostMapping("/add")
    public CommonResult<?> add(@RequestBody PositionEntity positionEntity){
        return this.positionService.add(positionEntity)>=1?CommonResult.success(null,"储位创建成功"):CommonResult.error(499,"网络异常");
    }

    /**
     * 根据储位名称模糊查询
     * @param keyWorld
     * @return
     */
    @GetMapping("/findListByNameLike")
    public CommonResult<?> findListByNameLike(@RequestParam("keyWorld")String keyWorld){
        return CommonResult.success(this.positionService.findByNameLike(keyWorld),"请求成功");
    }

    /**
     * 删除储位信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public CommonResult<?> delete(@PathVariable("id")Long id){
        return this.positionService.delete(id)>0 ?CommonResult.success(null,"删除成功"):CommonResult.error(499,"删除失败");
    }



}
